package menuService

import (
	"errors"
	menuDto "news_for_deepseek_interface/dto/admin/system/menu"
	"news_for_deepseek_interface/model"
	adminModel "news_for_deepseek_interface/model/admin"
)

func ListMenu(params menuDto.ListMenuRequest) (response []menuDto.ListMenuResponse, err error) {

	//实例化db
	db := model.GetInstance().GetDB()

	//查询条件
	if params.Title != "" {
		db = db.Where("title = ?", params.Title)
	}

	//查询数据
	var data []adminModel.AdminAuthRuleStruct
	if err = db.Find(&data).Error; err != nil {
		err = errors.New("查询失败")
		return
	}

	for _, v := range data {
		response = append(response, menuDto.ListMenuResponse{
			Id: v.Id,
			InitMenuRequest: menuDto.InitMenuRequest{
				ParentId:   v.ParentId,
				Title:      v.Title,
				Name:       v.Name,
				Path:       v.Path,
				Component:  v.Component,
				Rank:       v.Rank,
				ShowParent: v.ShowParent,
				Icon:       v.Icon,
				ShowLink:   v.ShowLink,
			},
		})
	}

	return
}
